<?php

namespace App\Service\Message\v1_1_2;

use App\Constants\ErrorCode;
use App\Helpers\AliyunUtil;
use App\Model\UserAutoMsg;
use App\Service\BaseService;

/**
 * 自动聊天消息删除
 */
class AutoMsgDelService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $recordId = $this->request->input('record_id', 0);
        $record = UserAutoMsg::find($recordId);
        if (!$recordId || $record->user_id != $userId) {
            return $this->setError(ErrorCode::PARAMETER_ERROR, '提交的记录ID参数错误');
        }
        $result = $record->update(['flag' => 0]);
        $msgType = $record->msg_type;
        $ret = [
            'msg_type' => $msgType,
            'msg_content' => UserAutoMsg::getUserTypeMsgs($userId, $msgType),
        ];
        return $ret;
    }
}
